<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>审批入库记录</title>
    <script type="text/javascript">
      var newWarehousingWin;
      var warehousingEntryId
      Ext.onReady(function(){
        var purchaseOrderNumber = Ext.create('Ext.form.field.Text', {
          fieldLabel: '采购单号',
          name: 'purchase_order_number',
          anchor: '100%'
        });

        var orderNumber = Ext.create('Ext.form.field.Text', {
          fieldLabel: '入库单号',
          anchor: '100%',
          name: 'order_number'
        });

        var vendor =  Ext.create('Ext.form.ComboBox', {
          fieldLabel: '供应商',
          store: vendorStore,
          valueField: 'id',
          displayField: 'name',
          name:'vendor_id',
          loadingText: '搜索中...',
          //pageSize: 10,
          minChars: 0,
          editable:false,
          anchor: '100%'
        });

        var beginDate = Ext.create('Ext.form.field.Date', {
          fieldLabel: '入库日期',
          name: 'begin_date',
          id: 'begin_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-01",         
          anchor: '100%',
          vtype: 'daterange',
          endDateField: 'end_date'
        });

        var endDate = Ext.create('Ext.form.field.Date', {
          fieldLabel: '至',
          name: 'end_date',
          id: 'end_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-01",          
          anchor: '100%',
          vtype: 'daterange',
          startDateField: 'begin_date'
        });

        var submitButton = Ext.create('Ext.Button', {
          text: '搜索',
          iconCls: 'finding',
          handler: function(){
            warehousingEntryDS.removeAll();
            warehousingEntryDS.getProxy().extraParams = queryFormPanel.getForm().getFieldValues();
            toolBar.moveFirst(); 
          }
        });

        var clearButton = Ext.create('Ext.Button', {
          text: '清空',
          width:50,
          handler: function(){
            queryFormPanel.form.reset();
          }
        });

        var queryFormPanel = Ext.create('Ext.form.Panel', {
          fieldDefaults: {
            labelWidth: 60,
            labelAlign: 'right'
          },
          width: screenWidth-165,
          frame : true,
          border:false,
          items: [{
              xtype: 'fieldset',
              defaults: {width: 1000},
              title: '查询条件',
              border: true,
              items: [{
                  layout: 'column',
                  xtype: 'container',
                  items: [{
                      columnWidth: .2,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [purchaseOrderNumber]
                    }, {
                      columnWidth: .2,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [orderNumber]
                    }, {
                      columnWidth: .3,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [vendor]
                    }]
                },{
                  layout: 'column',
                  xtype: 'container',
                  items: [{
                      columnWidth: .2,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [beginDate]
                    }, {
                      columnWidth: .2,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [endDate]
                    }, {
                      columnWidth: .2,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [submitButton]
                    }, {
                      columnWidth: .15,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [clearButton]
                    }]
                }]
            }]
        });
        //显示入库操作时的窗口介面。
        //----------------------------------------------------------------------
        //入库Grid Store
        //入库Grid Store
        var warehousingEntryDS =  Ext.create('Ext.data.Store', {
          //autoDestroy : true,
          model : 'WarehousingEntryModel',
          proxy : {
            type : 'ajax',
            url: '/warehousing_entry/getWarehousingEntriesByAuditStatus',
            reader : {
              type : 'json',
              root : 'root',
              totalProperty : 'totalProperty'// 数据集记录总数
            }
          },
          pageSize:pageSize,
          autoLoad:true
        });

        var toolBar = Ext.create('Ext.toolbar.Paging', {
          pageSize: pageSize,
          store: warehousingEntryDS,
          displayInfo: true,
          displayMsg: "显示第 {0} 条到 {1} 条记录，一共 {2} 条",
          emptyMsg: "没有记录"
        })
        
        //生成要订单的产品的Grid
        var warehousingEntryGrid = Ext.create('Ext.grid.Panel', {
          title:'入库单列表',
          store: warehousingEntryDS,
          columns : [Ext.create('Ext.grid.RowNumberer'),{
              header: 'DB',
              dataIndex: 'id',
              width: 50
            },{
              header: '公司',
              dataIndex: 'company_name',
              width: 50
            },{
              header: '采购单号',
              dataIndex: 'purchase_order_number',
              width: 130
            },{
              header: '采购订单审批状态',
              dataIndex: 'purchase_order_status',
              width: 110,
              renderer: auditingStatusRender
            },{
              header: '入库单号',
              dataIndex: 'order_number',
              width: 110
            },{
              header: '审批状态',
              dataIndex: 'auditing_status',
              width: 80,
              renderer: auditingStatusRender
            },{
              header: '供应商',
              dataIndex: 'vendor_name',
              width: 190
            },{
              header: '到仓库',
              dataIndex: 'warehouse_name',
              width: 80
            },{
              header: '入库日期',
              dataIndex: 'action_date',
              renderer: Ext.util.Format.dateRenderer('Y-m-d'),width: 80
            },{
              header: '操作员',
              dataIndex: 'employee_name',
              width: 70
            },{
              header: '部门',
              dataIndex: 'department_name',
              width: 70
            },{
              header: '备注',
              dataIndex: 'description',
              width: 130
            },{
              header: '生成日期',
              dataIndex: 'created_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),width: 115
            },{
              header: '修改日期',
              dataIndex: 'updated_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),width: 115
            }],
          selModel :Ext.create('Ext.selection.CheckboxModel'),
          loadMask: true,
          width: screenWidth-165,
          height: 315,
          frame: true,
          bbar: toolBar     
        });

        warehousingEntryGrid.on('itemdblclick', function(gridPanel, record,item,index,e,options){
          warehousingEntryId = warehousingEntryDS.getAt(index).get('id');
          var warehousingEntryNumber = warehousingEntryDS.getAt(index).get('order_number');
          //warehousingEntryDS.load();
          warehousingEntryDetailDS.removeAll();
          warehousingEntryDetailDS.load({params:{'id': warehousingEntryId}});
          warehousingEntryDetailGrid.setTitle("采购订单："+warehousingEntryNumber+"，的详细信息");
        });

        //--------------------------采购订单详细，双击后可显示数据----------------
        //采购订单Grid Store Detail
        //订单Grid Store Detail
        var warehousingEntryDetailDS =  Ext.create('Ext.data.Store', {
          //autoDestroy : true,
          model : 'WarehousingEntryDetailModel',
          proxy : {
            type : 'ajax',
            url: '/warehousing_entry/getWarehousingEntryDetailsById',
            reader : {
              type : 'json',
              root : 'root',
              totalProperty : 'totalProperty'// 数据集记录总数
            }
          }
        });

        //生成要订单的产品的Grid
        var warehousingEntryDetailGrid = Ext.create('Ext.grid.Panel', {
          title:'入库单详细列表',
          store: warehousingEntryDetailDS,
          columns : [Ext.create('Ext.grid.RowNumberer'),{
              header: 'DB',
              dataIndex: 'id',
              width: 60
            },{
              header: '产品名称',
              dataIndex: 'product_name',
              width: 230
            },{
              header: '产品编号',
              dataIndex: 'product_number',
              width: 80
            },{
              header: '规格',
              dataIndex: 'product_spec',
              width: 80
            },{
              header: '数量',
              align: 'right',
              dataIndex: 'quantity',
              width: 80
            },{
              header: '套装或单品',
              dataIndex: 'is_suit',
              width: 70
            },{
              header: '备注',
              dataIndex: 'description',
              width: 150
            }],
          loadMask: true,
          width: screenWidth-165,
          height: dgHeight,
          frame: true
          //title: '进货品种列表',
          //plain:true,
          //plugins: checkColumn,
        });

        //总的panel
        var workbenchPanel = Ext.create('Ext.form.Panel', {
          width: screenWidth-165,
          height: totalHeight,autoScroll:true,
          frame:false,          
          layout: {type: 'table',columns:1},          
          items:[queryFormPanel,warehousingEntryGrid,warehousingEntryDetailGrid]
        });
        workbenchPanel.render("warehousing_entry_list");
        
      })
    </script>
  </head>
  <body>
    <div id="warehousing_entry_list"></div>
  </body>
</html>
